﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.ComponentModel;
using System.Security.Claims;
using TomNet.App.Core.Contracts.Identity;
using TomNet.App.Model.DB.Identity;
using TomNet.App.Model.DTO;
using TomNet.Security.Claims;
using TomNet.SqlSugarCore.Entity;
namespace TomNet.App.Web.Controllers
{
    [Authorize]
    [Description("我的推广链接")]
    public class MyExtensionCodeController : Controller
    {
        private readonly IUsersContract _usersContract;        
        private readonly IUnitOfWork _unitOfWork;
        public MyExtensionCodeController(IUsersContract usersContract,            
            IUnitOfWork unitOfWork)
        {
            _usersContract = usersContract;
            _unitOfWork = unitOfWork;
        }
        [Description("我的推广链接")]
        [HttpGet]
        public IActionResult MyExtensionCodeList()
        {
            return View();
        }
        [Description("我的推广链接")]
        [HttpPost]
        public IActionResult MyExtensionCodeList(int page = 1, int limit = 20)
        {
            var userId = HttpContext.User.Identity.GetClaimValueFirstOrDefault(ClaimTypes.NameIdentifier);
            var entry = _usersContract.Entities.AsQueryable();            
            entry.Where(m=>m.Id.ToString()==userId).OrderBy(m => m.Id, OrderByType.Desc);
            int total = 0;
            var list = entry.ToPageList(page, limit, ref total);
            var result = new LayuiPageResult<Users>
            {
                Code = 0,
                Msg = "Success",
                Count = total,
                Data = list.ToArray()
            };
            return Json(result);
        }        
    }
}